package com.zz.parkingsystem.entity;

import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 车辆表
 * @TableName t_car
 */
@Data
public class Car implements Serializable {
    /**
     * 车辆id
     */
    private Integer carId;

    /**
     * 账户id
     */
    private Integer accId;

    /**
     * 车牌号id
     */
    private Integer clId;

    /**
     * 车牌号
     */
    private String carLicensePlate;

    /**
     * 绑定时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date carBindTime;

    private static final long serialVersionUID = 1L;

    /**
     * 根据用户id 和车牌号创建车辆信息
     *
     * @param userId 用户id
     * @param carLicensePlate 车牌号
     * @return 车辆信息
     */
    public static Car build(Integer userId, String carLicensePlate) {
        Car car = new Car();
        car.setClId(1);
        car.setAccId(userId);
        car.setCarBindTime(new Date());
        car.setCarLicensePlate(carLicensePlate);
        return car;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Car other = (Car) that;
        return (this.getCarId() == null ? other.getCarId() == null : this.getCarId().equals(other.getCarId()))
            && (this.getAccId() == null ? other.getAccId() == null : this.getAccId().equals(other.getAccId()))
            && (this.getClId() == null ? other.getClId() == null : this.getClId().equals(other.getClId()))
            && (this.getCarLicensePlate() == null ? other.getCarLicensePlate() == null : this.getCarLicensePlate().equals(other.getCarLicensePlate()))
            && (this.getCarBindTime() == null ? other.getCarBindTime() == null : this.getCarBindTime().equals(other.getCarBindTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getCarId() == null) ? 0 : getCarId().hashCode());
        result = prime * result + ((getAccId() == null) ? 0 : getAccId().hashCode());
        result = prime * result + ((getClId() == null) ? 0 : getClId().hashCode());
        result = prime * result + ((getCarLicensePlate() == null) ? 0 : getCarLicensePlate().hashCode());
        result = prime * result + ((getCarBindTime() == null) ? 0 : getCarBindTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", carId=").append(carId);
        sb.append(", accId=").append(accId);
        sb.append(", clId=").append(clId);
        sb.append(", carLicensePlate=").append(carLicensePlate);
        sb.append(", carBindTime=").append(carBindTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}